/* 带泛型的别名 */
type Person<T> = {
    name: string,
    age: number,
    favorite: T
}

const p1: Person<object> = {
    name: "",
    age: 0,
    favorite: {}
}

/* 类型索引 */
function getValueByKey<T extends Object, K extends (keyof T)>(obj: T, key: K) {
    return obj[key]
}
console.log({ a: 1, b: 2 }["c"]);

/* 索引签名 */
interface Animal {
    name: string,
    life: number,

    // 一堆string-any键值对
    [propName: string]: any
}

const a1: Animal = {
    name: "",
    life: 0,
    legs: 2,
    favorite: "骄奢淫逸"
}


/* 类型映射 */
interface Obj {
    a: any,
    b: any
}

type Obj2 = {
    // propName一个能打无数个
    // [propName: string]: any

    // PN一个打多个 具体几个取决于身后的联合类型
    [PN in ("a" | "b")]: any
}

const o2:Obj2 = {
    a: undefined,
    b: undefined
}